﻿using System;
using System.Collections.Generic;
using System.Text;
//new
using DataRecv.tools;
using System.Data;
using DataRecv.enums;
using DataRecv.db;
using System.Collections;

namespace DataRecv.models.device
{
    /// <summary>
    /// 特写区域参数
    /// </summary>
    public class FocusParam
    {
        /// <summary>
        /// 表名称
        /// </summary>
        private const string c_TableName = "FocusParam_t";
        /// <summary>
        /// 字段集合
        /// </summary>
        private const string c_Columns = "ip,left1,top1,right1,down1,left2,top2,right2,down2,left3,top3,right3,down3,left4,top4,right4,down4,left5,top5,right5,down5,left6,top6,right6,down6";
        /// <summary>
        /// 字段数量
        /// </summary>
        private const int c_ColumnsCount = 25;
        
        /// <summary>
        /// 设备IP
        /// </summary>
        public string ip;

        /// <summary>
        /// 车道1左
        /// </summary>
        public double left1;
        /// <summary>
        /// 车道1上
        /// </summary>
        public double top1;
        /// <summary>
        /// 车道1右
        /// </summary>
        public double right1;
        /// <summary>
        /// 车道1下
        /// </summary>
        public double down1;

        /// <summary>
        /// 车道2左
        /// </summary>
        public double left2;
        /// <summary>
        /// 车道2上
        /// </summary>
        public double top2;
        /// <summary>
        /// 车道2右
        /// </summary>
        public double right2;
        /// <summary>
        /// 车道2下
        /// </summary>
        public double down2;

        /// <summary>
        /// 车道3左
        /// </summary>
        public double left3;
        /// <summary>
        /// 车道3上
        /// </summary>
        public double top3;
        /// <summary>
        /// 车道3右
        /// </summary>
        public double right3;
        /// <summary>
        /// 车道3下
        /// </summary>
        public double down3;

        /// <summary>
        /// 车道4左
        /// </summary>
        public double left4;
        /// <summary>
        /// 车道4上
        /// </summary>
        public double top4;
        /// <summary>
        /// 车道4右
        /// </summary>
        public double right4;
        /// <summary>
        /// 车道4下
        /// </summary>
        public double down4;

        /// <summary>
        /// 车道5左
        /// </summary>
        public double left5;
        /// <summary>
        /// 车道5上
        /// </summary>
        public double top5;
        /// <summary>
        /// 车道5右
        /// </summary>
        public double right5;
        /// <summary>
        /// 车道5下
        /// </summary>
        public double down5;

        /// <summary>
        /// 车道6左
        /// </summary>
        public double left6;
        /// <summary>
        /// 车道6上
        /// </summary>
        public double top6;
        /// <summary>
        /// 车道6右
        /// </summary>
        public double right6;
        /// <summary>
        /// 车道6下
        /// </summary>
        public double down6;

        /// <summary>
        /// 空构造
        /// </summary>
        public FocusParam()
        {
            ip = "";
            left1 = 0;
            top1 = 0;
            right1 = 0;
            down1 = 0;
            left2 = 0;
            top2 = 0;
            right2 = 0;
            down2 = 0;
            left3 = 0;
            top3 = 0;
            right3 = 0;
            down3 = 0;
            left4 = 0;
            top4 = 0;
            right4 = 0;
            down4 = 0;
            left5 = 0;
            top5 = 0;
            right5 = 0;
            down5 = 0;
            left6 = 0;
            top6 = 0;
            right6 = 0;
            down6 = 0;
        }


        /// <summary>
        /// 查所有特写参数
        /// </summary>
        /// <returns>所有特写参数</returns>
        public static List<FocusParam> GetModels()
        {
            List<FocusParam> ans = null;
            DataTable dt = null;
            try
            {
                dt = DBHelper.GetInstance().Select(c_TableName, c_Columns, "1=1");
                if ((dt != null) && (dt.Rows != null) && (dt.Rows.Count > 0))
                {
                    ans = new List<FocusParam>();
                    foreach (DataRow row in dt.Rows)
                    {
                        FocusParam p = new FocusParam();
                        p.ip = row["ip"].ToString();
                        p.left1 = (row["left1"] == null) ? 0 : double.Parse(row["left1"].ToString());
                        p.top1 = (row["top1"] == null) ? 0 : double.Parse(row["top1"].ToString());
                        p.right1 = (row["right1"] == null) ? 0 : double.Parse(row["right1"].ToString());
                        p.down1 = (row["down1"] == null) ? 0 : double.Parse(row["down1"].ToString());
                        p.left2 = (row["left2"] == null) ? 0 : double.Parse(row["left2"].ToString());
                        p.top2 = (row["top2"] == null) ? 0 : double.Parse(row["top2"].ToString());
                        p.right2 = (row["right2"] == null) ? 0 : double.Parse(row["right2"].ToString());
                        p.down2 = (row["down2"] == null) ? 0 : double.Parse(row["down2"].ToString());
                        p.left3 = (row["left3"] == null) ? 0 : double.Parse(row["left3"].ToString());
                        p.top3 = (row["top3"] == null) ? 0 : double.Parse(row["top3"].ToString());
                        p.right3 = (row["right3"] == null) ? 0 : double.Parse(row["right3"].ToString());
                        p.down3 = (row["down3"] == null) ? 0 : double.Parse(row["down3"].ToString());
                        p.left4 = (row["left4"] == null) ? 0 : double.Parse(row["left4"].ToString());
                        p.top4 = (row["top4"] == null) ? 0 : double.Parse(row["top4"].ToString());
                        p.right4 = (row["right4"] == null) ? 0 : double.Parse(row["right4"].ToString());
                        p.down4 = (row["down4"] == null) ? 0 : double.Parse(row["down4"].ToString());
                        p.left5 = (row["left5"] == null) ? 0 : double.Parse(row["left5"].ToString());
                        p.top5 = (row["top5"] == null) ? 0 : double.Parse(row["top5"].ToString());
                        p.right5 = (row["right5"] == null) ? 0 : double.Parse(row["right5"].ToString());
                        p.down5 = (row["down5"] == null) ? 0 : double.Parse(row["down5"].ToString());
                        p.left6 = (row["left6"] == null) ? 0 : double.Parse(row["left6"].ToString());
                        p.top6 = (row["top6"] == null) ? 0 : double.Parse(row["top6"].ToString());
                        p.right6 = (row["right6"] == null) ? 0 : double.Parse(row["right6"].ToString());
                        p.down6 = (row["down6"] == null) ? 0 : double.Parse(row["down6"].ToString());
                        ans.Add(p);
                    }
                }
            }
            catch (Exception er)
            {
                ans = null;
                LogTool.log.Info("FocusParam.GetModels()" + er.Message);
            }
            finally
            {
                if (dt != null) dt.Dispose();
            }
            return ans;
        }

        /// <summary>
        /// 保存特写区域，没有则添加该特写区域
        /// </summary>
        /// <returns>结果</returns>
        public bool Save()
        {
            bool ans = false;
            try
            {
                string[] paramnames = c_Columns.Split(',');
                string[] paramvalues = new string[c_ColumnsCount];
                paramvalues[0] = ip.ToString();
                paramvalues[1] = left1.ToString();
                paramvalues[2] = top1.ToString();
                paramvalues[3] = right1.ToString();
                paramvalues[4] = down1.ToString();
                paramvalues[5] = left2.ToString();
                paramvalues[6] = top2.ToString();
                paramvalues[7] = right2.ToString();
                paramvalues[8] = down2.ToString();
                paramvalues[9] = left3.ToString();
                paramvalues[10] = top3.ToString();
                paramvalues[11] = right3.ToString();
                paramvalues[12] = down3.ToString();
                paramvalues[13] = left4.ToString();
                paramvalues[14] = top4.ToString();
                paramvalues[15] = right4.ToString();
                paramvalues[16] = down4.ToString();
                paramvalues[17] = left5.ToString();
                paramvalues[18] = top5.ToString();
                paramvalues[19] = right5.ToString();
                paramvalues[20] = down5.ToString();
                paramvalues[21] = left6.ToString();
                paramvalues[22] = top6.ToString();
                paramvalues[23] = right6.ToString();
                paramvalues[24] = down6.ToString();
                ans = DBHelper.GetInstance().EditorAddParam(c_TableName, paramnames, paramvalues);
            }
            catch { ans = false; }
            return ans;
        }

        
    }
}
